<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: application.php 136 2013-09-22 07:38:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 136 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:38:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if(!defined('DIR_FS_DOCUMENT_ROOT')) {
	define('DIR_FS_DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
	$local_install_path=str_replace('/installer','',$_SERVER['PHP_SELF']);
	$local_install_path=str_replace('index.php','',$local_install_path);
	$local_install_path=str_replace('install_step1.php','',$local_install_path);
	$local_install_path=str_replace('install_step2.php','',$local_install_path);
	$local_install_path=str_replace('install_step3.php','',$local_install_path);
	$local_install_path=str_replace('install_step4.php','',$local_install_path);
	$local_install_path=str_replace('install_step5.php','',$local_install_path);
	$local_install_path=str_replace('install_step6.php','',$local_install_path);
	$local_install_path=str_replace('install_step7.php','',$local_install_path);
	$local_install_path=str_replace('install_finished.php','',$local_install_path);
	define('DIR_FS_CATALOG', DIR_FS_DOCUMENT_ROOT . $local_install_path);
}

if(!defined('DIR_FS_INC'))
	define('DIR_FS_INC', DIR_FS_CATALOG.'inc/');
if(!defined('DIR_WS_CLASSES'))
	define('DIR_WS_CLASSES', DIR_FS_CATALOG.'includes/classes/');

function __autoload($class_name) {
	if(file_exists(DIR_WS_CLASSES.'class.'.$class_name.'.php'))
		require_once(DIR_WS_CLASSES.'class.'.$class_name.'.php');
}

if(isset($_GET['step']) && $_GET['step'] != '0' && $_GET['step'] != '1' && $_GET['step'] != '2')
	require(DIR_FS_CATALOG.'includes/database_tables.php');
	
require(DIR_FS_CATALOG.'includes/filenames.php');
include(DIR_FS_CATALOG.'includes/classes/adodb/adodb.inc.php');

session_start();

error_reporting(E_ALL & ~E_NOTICE);

include('language/german.php');

require(DIR_FS_INC.'inc.not_null.php');
require(DIR_FS_INC.'inc.get_img_size.php');
require(DIR_FS_INC.'inc.mercari_version.php');
require(DIR_FS_INC.'inc.check_agent.php');
require(DIR_FS_INC.'inc.encrypt_password.php');
require(DIR_FS_INC.'inc.validate_email.php');
require(DIR_FS_INC.'inc.href_link.php');
require(DIR_FS_INC.'inc.redirect.php');
require(DIR_FS_INC.'inc.gdlib_check.php');
require(DIR_FS_INC.'inc.draw_pull_down_menu.php');
require(DIR_FS_INC.'inc.draw_input_field.php');
require(DIR_FS_INC.'inc.get_country_list.php');
require(DIR_FS_INC.'inc.draw_selection_field_installer.php');
require(DIR_FS_INC.'inc.draw_input_field_installer.php');
require(DIR_FS_INC.'inc.draw_password_field_installer.php');
require(DIR_FS_INC.'inc.draw_hidden_field_installer.php');
require(DIR_FS_INC.'inc.draw_checkbox_field_installer.php');
require(DIR_FS_INC.'inc.draw_radio_field_installer.php');
require(DIR_FS_INC.'inc.image.php');

if(!defined('DIR_WS_ICONS'))
	define('DIR_WS_ICONS','images/');

function mouseOverJS($title='',$text,$img='',$width='') {
	if($text !='') {
		$fade_out = ', FADEOUT, 500';
		$padding = ', PADDING, 10';
		if($width =='')
			$w = ', WIDTH, 400';
		else
			$w = ', WIDTH, '.$width;
		$follow_mouse = ', FOLLOWMOUSE, false';
		if($title !='')
			$titel = ', TITLE, \''.$title.'\'';
		if($img !='')
			$text = '<img class=&quot;img_border&quot; src=&quot;'.$img.'&quot; alt=&quot;'.$title.'&quot; align=&quot;left&quot; style=&quot;margin: 0 10px 10px 0&quot; >'.$text;
		$over = ' onmouseover="Tip(\''.$text.'\''.$titel.''.$backg_color.''.$border_color.''.$fade_in.''.$fade_out.''.$padding.''.$color.''.$w.''.$follow_mouse.''.$shadow.''.$title_bg.''.$title_color.')" onmouseout="UnTip()"';
		return $over;
	} else
	return;
}

function get_help($id ='', $title ='') {
	if(!empty($id)) {
		$help = '<a class="help_tip" href="javascript:void(0);"';
		if(!empty($title))
			$help .= 'title="'.$title.'"';
		$help .= ' rel="includes/get_faq_help.php?id='.$id.'"><img src="images/icons/question-balloon.png" alt="" /></a>';
		return $help;
	} else
		return;
}

function check_version($mini='5.1.0') {
	$dummy=phpversion();
	sscanf($dummy,"%d.%d.%d%s",$v1,$v2,$v3,$v4);
	sscanf($mini,"%d.%d.%d%s",$m1,$m2,$m3,$m4);
	if($v1>$m1)
	   return(1);
	elseif($v1<$m1)
	 return(0);
	if($v2>$m2)
	   return(1);
	elseif($v2<$m2)
	   return(0);
	if($v3>$m3)
	  return(1);
	elseif($v3<$m3)
	   return(0);
	if((!$v4)&&(!$m4))
	   return(1);
	if(($v4)&&(!$m4)) {
	  $dummy=strpos($v4,"pl");
	   if(is_integer($dummy))
	      return(1);
	   return(0);
	}
	elseif((!$v4)&&($m4)) {
	  $dummy=strpos($m4,"rc");
	   if(is_integer($dummy))
	      return(1);
	   return(0);
	}
	return(0);
}

function loadSQL($sql_file, $prefix = DB_PREFIX) {
	global $db;
	$restore_query = '';
	        
	if (file_exists($sql_file)) {
		$fd = fopen($sql_file, 'rb');
		$restore_query = fread($fd, filesize($sql_file));
		fclose($fd);
		
	} else {
	    $db_error = 'Die SQL-Datei '.$sql_file.' konnte nicht gefunden werden!';
	    return false;
	}
	
	$sql_array = array();
	$sql_length = strlen($restore_query);
	$pos = strpos($restore_query, ';');
	for ($i=$pos; $i<$sql_length; $i++) {
		if ($restore_query[0] == '#') {
			$restore_query = ltrim(substr($restore_query, strpos($restore_query, "\n")));
			$sql_length = strlen($restore_query);
			$i = strpos($restore_query, ';')-1;
			continue;
		}
		if ($restore_query[($i+1)] == "\n") {
			for ($j=($i+2); $j<$sql_length; $j++) {
				if (trim($restore_query[$j]) != '') {
					$next = substr($restore_query, $j, 6);
					if ($next[0] == '#') {
						for ($k=$j; $k<$sql_length; $k++) {
							if ($restore_query[$k] == "\n") 
								break;
						}
						$query = substr($restore_query, 0, $i+1);
						$restore_query = substr($restore_query, $k);
						$restore_query = $query . $restore_query;
						$sql_length = strlen($restore_query);
						$i = strpos($restore_query, ';')-1;
						continue 2;
					}
					break;
				}
			}
			if ($next == '')
				$next = 'insert';
			
			if(preg_match("/create/i", $next) || preg_match("/alter/i", $next) || preg_match("/insert/i", $next) || preg_match("/drop t/i", $next) ) {
				$next = '';
				$sql_array[] = substr($restore_query, 0, $i);
				$restore_query = ltrim(substr($restore_query, $i+1));
				$sql_length = strlen($restore_query);
				$i = strpos($restore_query, ';')-1;
			}
		}
	}
	
	for ($i=0; $i < sizeof($sql_array); $i++) {
		$sql_array[$i] = str_replace('sql_prefix_', $prefix, $sql_array[$i]);
		$db->Execute($db->Prepare($sql_array[$i]));
	}
	return true;
}

$message_stack = new message_stack();
?>